#include <GenericTypeDefs.h>
#include "p18f26k22.h"
#include "isrs.h"
#include "uart.h"



//Local Variables

UINT8 counter = 0;
BOOL read_adc = FALSE;
//----------------------------------------------------------------------------
// High priority interrupt vector

//#pragma code InterruptVectorHigh = 0x08
//void InterruptVectorHigh (void)
//{
//  _asm
//    goto InterruptHandlerHigh //jump to interrupt routine
//  _endasm
//}
//#pragma code

//----------------------------------------------------------------------------
// High priority interrupt routine

//#pragma interrupt InterruptHandlerHigh
void interrupt InterruptHandlerHigh ()
{
  if (PIR1bits.TMR1IF)
    {
      //interrupt at 2k
      TMR1L           = 0x82;        // 0xFFFF - 0x7D (1000) = 0xFF82
      TMR1H           = 0xFF;        //reset
      PIR1bits.TMR1IF = 0;            //clear interrupt flag
      counter++;

      CLK = (counter%2) ? 0b1 : 0b0;
/*
        LATBbits.LATB6 = 0b0;
        LATBbits.LATB6 = 0b1;
*/
      if (counter == 1)
      {
          /* MkII board */
          BIT_LOAD = 0;
          /* MkI board */
          //BIT_LOAD = 1;
      }
      if (counter == 15)
      {
          /* MkII board */
          BIT_LOAD = 1;
          /* MkI board */
          //BIT_LOAD = 0;
      }
      if (counter >= 16)
      {
          counter = 0;
      }
    }
   if (PIR5bits.TMR4IF)
   {
      PIR5bits.TMR4IF = 0;            //clear interrupt flag
      read_adc = TRUE;
   }
}


//#pragma code InterruptVectorLow = 0x18
//void InterruptVectorLow (void)
//{
//  _asm
//    goto InterruptHandlerLow //jump to interrupt routine
//  _endasm
//}
//#pragma code

//----------------------------------------------------------------------------
// Low priority interrupt routine

//#pragma interruptlow InterruptHandlerLow
void low_priority interrupt InterruptHandlerLow ( void )
{
    if(TXIF)
    {
        //PIR3bits.TX2IF = 0b0; //cleared when writing to txmt shft reg
        tx_midi_command_byte();
    }
}